﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DiffisionWithDecomposition
{
    /// <summary>
    /// Singleton class to represent time
    /// </summary>
    public class Time
    {
        private long _nanoSeconds;
        private static Time instance;

        public static Time Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new Time();
                    return instance;
                }
                else
                {
                    return instance;
                }
            }
        }

        private Time()
        {
            _nanoSeconds = 0;    //initial time
        }

        public void SetTimeToZero()
        {
            _nanoSeconds = 0;
        }

        public void AdvanceTime(long to)
        {
            instance._nanoSeconds = to;
        }

        public long Now { get { return _nanoSeconds; } }

        public long GetTimeAfterNanoSeconds(long passingNanoSeconds)
        {
            return _nanoSeconds + passingNanoSeconds;
        }

        public double GetTimeInSeconds()
        {
            return (double)Now / 1000000000;
        }

        public void PrintTime()
        {
            Console.WriteLine(_nanoSeconds);
        }

        public void PrintTimeInSeconds()
        {
            Console.WriteLine("Time (sec) " + _nanoSeconds / (double)1000000000);
        }
    }
}
